<?php


namespace apps\marriage\app\mp\controller;


use apps\marriage\core\service\MemberImagesService;
use think\Request;

class MemberImagesController extends BaseMarriageMpController
{
    /**
     * @var MemberImagesService
     */
    private $memberImagesService;

    protected function init()
    {
        parent::init();
        $this->memberImagesService = service('MemberImages', SERVICE_NAMESPACE);
    }

    public function all()
    {
        $images = $this->memberImagesService->getAllByUserId($this->user['id']);
        return $this->success(['images' => $images]);
    }

    public function my_all()
    {
        $images = $this->memberImagesService->getAll(['user_id' => $this->user['id']]);
        return $this->success(['images' => $images]);
    }

    public function upload(Request $request)
    {
        $fileId = $request->param('file_id');
        $this->memberImagesService->create([
            'user_id' => $this->user['id'],
            'file_id' => $fileId,
            'add_time' => time()
        ]);
        return $this->success();
    }

    public function delete(Request $request)
    {
        $fileId = $request->param('file_id');
        $this->memberImagesService->delete([
            'user_id' => $this->user['id'],
            'file_id' => $fileId,
        ]);
        return $this->success();
    }
}